package com.bocek.chakmapoint.view.slideshow;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.Iterator;

import javax.swing.JPanel;

import com.bocek.chakmapoint.controller.SlideEditController;
import com.bocek.chakmapoint.controller.SlideshowController;
import com.bocek.chakmapoint.model.SlideItem;
import com.bocek.chakmapoint.model.SlideStyleList;

/**
 * Slide show panel for a single slide.
 * 
 * @author  Baris Sencan
 * @version 1.0
 */
public class SlideshowPanel extends JPanel {
	private static final long serialVersionUID = -3443194890465412817L;
	private static SlideshowPanel instance = null;
	
	public static SlideshowPanel getInstance() {
		
		if (instance == null) {
			instance = new SlideshowPanel();
		}
		return instance;
	}

	/**
	 * Create the panel.
	 */
	private SlideshowPanel() {

	}

	protected void paintComponent(Graphics g) {
		Iterator<SlideItem> iterator = null;
		int styleIndex = SlideStyleList.getInstance().getCurrent();
		
		super.paintComponents(g);
		
		g.setColor(SlideStyleList.getInstance().getStyle(styleIndex).getBackground());
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setColor(SlideStyleList.getInstance().getStyle(styleIndex).getColor());
		
		iterator = SlideshowController.getInstance().getItemIterator();
		
		while (iterator != null && iterator.hasNext()) {
			iterator.next().draw(g);
		}
		
		if (SlideEditController.getInstance().isNumberShown())
			g.drawString(
					Integer.toString(SlideshowController.getInstance().getCurrentSlideNo()),
					10,
					470);
		
		/*
		BufferedImage bi = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);
		Image scaledImage = bi.getScaledInstance(getWidth(), getHeight(), Image.SCALE_DEFAULT);
		
		g.setColor(SlideStyleList.getInstance().getStyle(styleIndex).getBackground());
		g.fillRect(0, 0, getWidth(), getHeight());
		
		Graphics2D g2d = (Graphics2D) g;
		g2d.drawImage(bi, 0, 0, null);*/
	}
}
